public class LeetCode671 {

    int res = -1;

    public int findSecondMinimumValue(TreeNode root) {
        dfs(root, root.val);
        return res;
    }

    void dfs(TreeNode root, int cur) {
        if (root == null) {
            return;
        }
        if (root.val != cur) {
            if (res == -1) {
                res = root.val;
            } else {
                res = Math.min(root.val, res);
                return;
            }
        }
        dfs(root.left, cur);
        dfs(root.right, cur);
    }

}
